package server

import (
	"app/daos"
	"github.com/fwhezfwhez/errorx"
)

type Register interface {
	PutKeyWithLease(lease int64) error
	ListenKeepChan()
	Close() error
}

func NewServiceRegister(key, value string, lease int64) (Register, error) {
	client := daos.GetEtcd()
	srv := &ServiceRegister{
		Cli:   client,
		Key:   key,
		Value: value,
	}

	if err := srv.PutKeyWithLease(lease); err != nil {
		return nil, errorx.Wrap(err)
	}

	return srv, nil
}
